<?php 
if(KT!='KhiThe') exit;
class links_model extends khithe_mysql{

	public function getlinks()
	{		
		$select = "SELECT * FROM ".links." ORDER BY `Order` ASC, ID DESC";
		$result = parent::SelectMySQL($select);
		parent::CloseConnection();
		return$result; 
	}
	
	public function getlinkID($ID){
		
		$ID = parent::checkStrMySQL($ID);
		$select = "SELECT * FROM ".links." WHERE ID = '".$ID."'";
		$result= parent::SelectMySQL($select);
		parent::CloseConnection();
		return $result;
	}
	
	public function setCheckedlink($ID,$Val)
	{
		$ID = parent::checkStrMySQL($ID);
		$update = "UPDATE ".links." SET Status='".$Val."'  WHERE ID = '".$ID."' ";
		parent::CloseConnection();
		return parent::UpdateInsertMySQL($update);
	}
	
	public function delCheckedlink($ID)
	{
		$ID = parent::checkStrMySQL($ID);
		$del = "DELETE FROM ".links." WHERE ID='".$ID."' ";
		parent::CloseConnection();
		return parent::DeleteMySQL($del);
	}
	
	public function updateInsertlink($_POST)
	{
		$ID = parent::checkStrMySQL($_POST['linksID']);
		$linkname = parent::checkStrMySQL($_POST['txt_linksName']);
		$link = parent::checkStrMySQL($_POST['txt_links']);
		$Picture = parent::checkStrMySQL($_POST['Picture']);
		$order = parent::checkStrMySQL($_POST['orderLink']);
		
		if($_POST['aclink']=='edit'){
			$Pic = $Picture!='InvalidFile'?" Picture='".$Picture."', ":"";
			$query = "UPDATE ".links." SET Title='".$linkname."',Link='".$link."', ".$Pic." `Order`='".$order."' WHERE ID = '".trim($ID)."'";
		
		}else if($_POST['aclink']=='add'){
			$Pic = $Picture!='InvalidFile'?" Picture='".$Picture."', ":" Picture='logo.png',";
			$query = "INSERT INTO ".links."(Title,Link,Picture,`Order`,`Status`)VALUES('".$linkname."','".$link."','".$Picture."','".$order."','true')";
		}
		
		parent::CloseConnection();
		return parent::UpdateInsertMySQL($query);
		
	}
}
?>